package org.neo4j.test.rule;

import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
import org.neo4j.logging.LogProvider;
import org.neo4j.test.TestDatabaseManagementServiceBuilder;

/**
 * JUnit @Rule for configuring, creating and managing an ImpermanentGraphDatabase instance.
 */
@Deprecated
public class ImpermanentDbmsRule extends DbmsRule {
    private final LogProvider userLogProvider;
    private final LogProvider internalLogProvider;

    public ImpermanentDbmsRule() {
        this(null);
    }

    public ImpermanentDbmsRule(LogProvider logProvider) {
        this.userLogProvider = logProvider;
        this.internalLogProvider = logProvider;
    }

    @Override
    public ImpermanentDbmsRule startLazily() {
        return (ImpermanentDbmsRule) super.startLazily();
    }

    @Override
    protected DatabaseManagementServiceBuilder newFactory() {
        return maybeSetInternalLogProvider(
                maybeSetUserLogProvider(new TestDatabaseManagementServiceBuilder().impermanent()));
    }

    protected final TestDatabaseManagementServiceBuilder maybeSetUserLogProvider(
            TestDatabaseManagementServiceBuilder factory) {
        return (userLogProvider == null) ? factory : factory.setUserLogProvider(userLogProvider);
    }

    protected final TestDatabaseManagementServiceBuilder maybeSetInternalLogProvider(
            TestDatabaseManagementServiceBuilder factory) {
        return (internalLogProvider == null) ? factory : factory.setInternalLogProvider(internalLogProvider);
    }
}
